'''
    说明：这个文件主要介绍日志的使用
'''

import logging

#可以设置日志级别，比如设置INFO，那么就看不到DEBUG级别的日志了
#logging.basicConfig(level=logging.ERROR, format=' %(asctime)s - %(levelname)s- %(message)s')
#logging.basicConfig(level=logging.INFO, format=' %(asctime)s - %(levelname)s- %(message)s')
#logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %(levelname)s- %(message)s')

#将日志记录到控制台
logging.basicConfig(filename='myProgramLog.txt', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')

logging.debug('Start of program')
def factorial(n):
    logging.debug('Start of factorial(%s%%)' % (n))
    total = 1
    for i in range(n + 1):
        total *= i
        logging.debug('i is ' + str(i) + ', total is ' + str(total))
        logging.debug('End of factorial(%s%%)' % (n))
    return total

print(factorial(5))
logging.debug('End of program')